using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace G15_Agent.Models.Mapping
{
    public class HoaDonKHMap : EntityTypeConfiguration<HoaDonKH>
    {
        public HoaDonKHMap()
        {
            // Primary Key
            this.HasKey(t => t.MaHoaDon);

            // Properties
            this.Property(t => t.MaHoaDon)
                .IsRequired()
                .HasMaxLength(15);

            this.Property(t => t.MaNguoiDung)
                .HasMaxLength(15);

            // Table & Column Mappings
            this.ToTable("HoaDonKH");
            this.Property(t => t.MaHoaDon).HasColumnName("MaHoaDon");
            this.Property(t => t.MaNguoiDung).HasColumnName("MaNguoiDung");
            this.Property(t => t.NgayLap).HasColumnName("NgayLap");
            this.Property(t => t.DonGia).HasColumnName("DonGia");
            this.Property(t => t.TrangThai).HasColumnName("TrangThai");

            // Relationships
            this.HasOptional(t => t.NguoiDung)
                .WithMany(t => t.HoaDonKHs)
                .HasForeignKey(d => d.MaNguoiDung);

        }
    }
}
